package org.jetlinks.community.mstn.entity;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.Setter;
import org.hswebframework.ezorm.rdb.mapping.annotation.ColumnType;
import org.hswebframework.ezorm.rdb.mapping.annotation.DefaultValue;
import org.hswebframework.ezorm.rdb.mapping.annotation.EnumCodec;
import org.hswebframework.ezorm.rdb.mapping.annotation.JsonCodec;
import org.hswebframework.web.api.crud.entity.GenericEntity;
import org.hswebframework.web.api.crud.entity.RecordCreationEntity;
import org.hswebframework.web.api.crud.entity.RecordModifierEntity;
import org.hswebframework.web.crud.generator.Generators;
import org.hswebframework.web.validator.CreateGroup;
import org.jetlinks.community.device.enums.DeviceState;
import org.jetlinks.community.mstn.enums.DataSourceType;

import javax.persistence.Column;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import java.sql.JDBCType;
import java.util.Map;

@Table(name = "m_device_alias")
@Getter
@Setter
public class DeviceAliasEntity extends GenericEntity<String> implements RecordCreationEntity {

    @Column(name = "category_id", length = 64)
    @Schema(description = "分类ID")
    private String categoryId;

    @Column(name = "category_name")
    @Schema(description = "分类名")
    private String categoryName;

    @Column(name = "nickname")
    @Schema(description = "别名")
    private String nickname;

    @Column(name = "description")
    @Schema(description = "备注")
    private String description;

    @Column(name = "site_id", length = 64)
    @Schema(description = "站点ID")
    private String siteId;
    @Column(name = "site_name")
    @Schema(description = "站点名称")
    private String siteName;

    @Column(name = "group_id", length = 64)
    @Schema(description = "分组ID")
    private String groupId;

    @Column(name = "group_name")
    @Schema(description = "分组名称")
    private String groupName;

    @Schema(description = "保养间隔")
    @Column(name = "interval")
    private Long interval;

    @Schema(description = "安装时间")
    @Column(name = "installTime")
    private Long installTime;

    @Schema(description = "说明")
    private String describe;

    @Column(length = 16)
    @EnumCodec
    @ColumnType(javaType = String.class)
    @DefaultValue("device")
    @NotNull(groups = CreateGroup.class)
    @Schema(description = "数据源类型")
    private DataSourceType dataSourceType;

    @Column(name = "alias_metadata")
    @ColumnType(jdbcType = JDBCType.LONGVARCHAR)
    @Schema(description = "物模型")
    private String aliasMetadata;

    @Column(name = "configuration")
    @ColumnType(jdbcType = JDBCType.LONGVARCHAR)
    @JsonCodec
    @Schema(description = "配置信息")
    private Map<String, Object> configuration;


    @Column(name = "creator_id", updatable = false)
    @Schema(
        description = "创建者ID(只读)"
        ,accessMode = Schema.AccessMode.READ_ONLY
    )
    private String creatorId;

    @Column(name = "creator_name", updatable = false)
    @Schema(
        description = "创建者名称(只读)"
        ,accessMode = Schema.AccessMode.READ_ONLY
    )
    private String creatorName;

    @Column(name = "create_time", updatable = false)
    @DefaultValue(generator = Generators.CURRENT_TIME)
    @Schema(
        description = "创建时间(只读)"
        , accessMode = Schema.AccessMode.READ_ONLY
    )
    private Long createTime;
}
